package br.com.fiap.enumeration;

import br.com.fiap.beans.MenuBean;

public enum TipoUsuario {

	ADMINISTRADOR("0","Administrador"),
	FUNCIONARIO("1","Funcionario"),
	CLIENTE("2","Cliente");
	
	private String key;
	private String label;
	
	private TipoUsuario (String key, String label) {
		this.key = key;
		this.label = label;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public static TipoUsuario getEnumByKey(String key) {
		
		for (TipoUsuario tipo : TipoUsuario.values()) {
			if (tipo.key.equals(key)) {
				return tipo;
			}
		}
		
		return null;
	}
	
	public static MenuBean populaRoles(TipoUsuario tipoUsuario) {
		
		MenuBean menuBean = new MenuBean();
		
		if(tipoUsuario.getKey().equals("0")){
			menuBean.setCliente(true);
		}else if(tipoUsuario.getKey().equals("1")){
			menuBean.setVoo(true);
			menuBean.setTrecho(true);
		}else if(tipoUsuario.getKey().equals("2")){
			menuBean.setCompra(true);
			menuBean.setReserva(true);
		}
		return menuBean;
	}
}
